﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Volo.Abp.EntityFrameworkCore.Modeling;

namespace Loong.Admin.AuditLogging
{
    public class AuditLogActionConfiguration : IEntityTypeConfiguration<AuditLogAction>
    {
        public void Configure(EntityTypeBuilder<AuditLogAction> b)
        {
            b.ToTable("AuditLogAction");

            b.ConfigureByConvention();

            b.Property(x => x.AuditLogId).HasColumnName(nameof(AuditLogAction.AuditLogId));
            b.Property(x => x.ServiceName).HasMaxLength(AuditLogActionConsts.MaxServiceNameLength).HasColumnName(nameof(AuditLogAction.ServiceName));
            b.Property(x => x.MethodName).HasMaxLength(AuditLogActionConsts.MaxMethodNameLength).HasColumnName(nameof(AuditLogAction.MethodName));
            b.Property(x => x.Parameters).HasMaxLength(AuditLogActionConsts.MaxParametersLength).HasColumnName(nameof(AuditLogAction.Parameters));
            b.Property(x => x.ExecutionTime).HasColumnName(nameof(AuditLogAction.ExecutionTime));
            b.Property(x => x.ExecutionDuration).HasColumnName(nameof(AuditLogAction.ExecutionDuration));

            b.HasIndex(x => new { x.AuditLogId });
            b.HasIndex(x => new { x.TenantId, x.ServiceName, x.MethodName, x.ExecutionTime });

            b.ApplyObjectExtensionMappings();
        }
    }
}
